<?php

use yii\db\Migration;

class m171228_060709_create_wechat_menu extends Migration
{

    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%nav_menu}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(100)->defaultValue(null)->comment('菜单名称'),
                'controllers' => $this->string(100)->defaultValue(null)->comment('控制器'),
                'action' => $this->string(100)->defaultValue(null)->comment('方法'),
                'param' => $this->string(100)->defaultValue(null)->comment('参数'),
                'status' => $this->smallInteger(1)->defaultValue(1)->comment('1 启用 2 禁用'),
                'open_mode' => $this->smallInteger(1)->defaultValue(0)->comment('0 直接跳转 1 新页面打开'),
                'type_id' => $this->smallInteger(1)->defaultValue(0)->comment('三大类（1 益智  2 音乐  3  形体）'),
                'admin_id' => $this->integer()->defaultValue(0)->comment('管理员id'),
                'sort_order' => $this->integer()->defaultValue(0)->comment('排序'),
                'position' => $this->smallInteger(3)->defaultValue(2)->comment('位置（1 顶 2 左侧 3 底部）'),
                'type' => $this->string(20)->defaultValue(null)->comment('类型 新闻（news），老师（teacher）,商品（goods）'),
                'created_at' => $this->integer()->defaultValue(0)->comment('添加时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%nav_menu}}');
        }
    }

}
